package com.sparrow.source.controller;

import com.sparrow.source.common.dto.Result;
import com.sparrow.source.common.enums.ResultEnum;
import com.sparrow.source.service.IIasFaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author bryceyung
 * @since 2024/11/20
 */
@RequestMapping("/v1/face")
@Controller
public class FaceController {

    @Autowired
    private IIasFaceService faceService;

    @PostMapping("add")
    @ResponseBody
    public Result addFaceInfo(@RequestParam("userId") Integer userId, @RequestParam("files") MultipartFile[] files) {
        if (files.length > 6) {
            return Result.build(ResultEnum.NOT_ACCEPTABLE).setMessage("一次最多可上传6张图片");
        }
        return faceService.addFaceImage(userId, files);
    }

    @PostMapping("update")
    @ResponseBody
    public Result updateFaceInfo(@RequestParam("faceId") Integer faceId,@RequestParam("files") MultipartFile[] files){
        return faceService.updateFaceImage(faceId, files);
    }

    @PostMapping("delete")
    @ResponseBody
    public Result deleteFace(@RequestParam("faceId") Integer faceId){
        return Result.build(ResultEnum.SUCCESS).setObject(faceService.delete(faceId));
    }

}
